const { DataTypes } = require("sequelize");
const Classify = require("./classify.model");
const requelize = require("../db/sequelize");

const SiteInclusion = requelize.define(
  "db_siteInclusion",
  {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      unique: true,
      primaryKey: true,
      comment: "ID",
    },
    added_by: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "添加人ID",
    },
    type: {
      type: DataTypes.INTEGER(2),
      allowNull: true,
      comment: "类型(是否已收录)",
    },
    classify_id: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "站点所属的分类ID",
    },
    title: {
      type: DataTypes.STRING(200),
      allowNull: false,
      comment: "站点标题",
    },
    link: {
      type: DataTypes.STRING(200),
      allowNull: false,
      comment: "站点链接",
    },
    description: {
      type: DataTypes.STRING,
      allowNull: false,
      comment: "站点简介",
    },
    email: {
      type: DataTypes.STRING,
      allowNull: true,
      comment: "邮箱",
    },
    phone_number: {
      type: DataTypes.STRING(11),
      allowNull: true,
      comment: "手机号",
    },
    nickname: {
      type: DataTypes.STRING(20),
      allowNull: true,
      comment: "昵称",
    },
  },
  {
    tableName: "db_siteInclusion",
    comment: "站点收录",
  }
);

SiteInclusion.belongsTo(Classify, {
  foreignKey: "classify_id",
  targetKey: "id",
  as: "classifyInfo",
});
// 注释掉的代码块：这里原本是一个同步数据库表结构的调用，使用时需要解除注释并谨慎操作，因为它会强制同步表结构，可能导致数据丢失
// SiteInclusion.sync({ force: true });

// 导出用户模型，供其他模块使用
module.exports = SiteInclusion;
